package com.senthink.gl.business.common.util;
import org.springframework.util.ResourceUtils;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

public class UploadUtils {
        public final static String IMG_PATH_PREFIX = "static/upload";
        public final static String VIDEO_PATH_PREFIX = "static/upload";
        public static File getDirFile() throws FileNotFoundException, UnsupportedEncodingException {
                // 构建上传文件的存放 “文件夹” 路径
                String mediapath = ResourceUtils.getURL("classpath:").getPath()+"/";
                mediapath = URLDecoder.decode(mediapath, "utf-8");
                String realPath = mediapath.replace('/', '\\').substring(1,mediapath.length());
                //用于查看路径是否正确
                File path = new File(realPath);
                if(!path.exists()) path = new File("");
                String fileDirPath = new String(path.getAbsolutePath()+"/" + IMG_PATH_PREFIX);
                File fileDir = new File(fileDirPath);
                if(!fileDir.exists()){
                        // 递归生成文件夹
                        fileDir.mkdirs();
                }
                return fileDir;
        }

/*
public static File getVideoDirFile() throws FileNotFoundException, UnsupportedEncodingException {
        // 构建上传文件的存放 “文件夹” 路径
        String mediaUrl = ResourceUtils.getURL("classpath:").getPath()+"/";
        mediaUrl = URLDecoder.decode(mediaUrl, "utf-8");
        String realPath = mediaUrl.replace('/', '\\').substring(1,mediaUrl.length());
        //用于查看路径是否正确
        File path = new File(realPath);
        if(!path.exists()) path = new File("");
        String fileDirPath = new String(path.getAbsolutePath() + "/" + VIDEO_PATH_PREFIX);
        File fileDir = new File(fileDirPath);
        if(!fileDir.exists()){
            // 递归生成文件夹
            fileDir.mkdirs();
        }
        return fileDir;
    }
*/


}
